<template>
	<view>
		<uni-group title="全部评论">
			<view class="comment" v-for="(res, index) in commentList" :key="res.id">
				<view class="left">
					<image src="../../../../static/uview/example/js_select_bak.png" mode="aspectFill"></image>
				</view>
				<view class="right">
					<view class="top">
						<view class="name">{{ res.userName }}</view>
						<view class="like" :class="{ highlight: res.myLikeState }">
							<u-icon v-if="!res.myLikeState" name="thumb-up" :size="30" color="#9a9a9a"
								@click="getLike(index,res.id,res.myLikeState)"></u-icon>
							<u-icon v-if="res.myLikeState" name="thumb-up-fill" :size="30" @click="getLike(index,res.id,res.myLikeState)"></u-icon>
						</view>
					</view>
					<view class="content">{{ res.content }}</view>
					
					<view class="bottom">
						{{ res.createTime }}
						<view class="reply">回复</view>
					</view>
				</view>
			</view>
		</uni-group>
		<view class="" style="height: 20vh;">
			
		</view>
		<uni-group style="position: fixed;right: 0%;bottom: 0%;left: 0%;z-index: 99;">
			<view class="u-flex">
				<uni-easyinput v-model="value"></uni-easyinput>
				<button @click="ping" type="primary">发送</button>
			</view>
		</uni-group>
	</view>
</template>

<script>
	import api from 'commer/apiURL.js'
	export default {
		data() {
			return {
				value:'',
				id:'',
				base:api.baseurl,
				commentList: []
			}
		},
		onLoad(options) {
			this.getlun(options.id)
			this.id = options.id
		},
		methods: {
			ping(){
				this.$post(this.base+'/prod-api/api/digital-library/library-comment',{
					libraryId:this.id,
					content:this.value
				}).then((res)=>{
					if(res.code == 200){
						uni.showToast({
							title:'评论成功'
						})
						this.value = ''
						this.getlun(this.id)
					}		
				})
			},
			getlun(id) {
				this.$get(this.base + '/prod-api/api/digital-library/library-comment/list', {
					libraryId: id
				}).then((res) => {
					console.log(res)
					this.commentList = res.data
				})
			},
			getLike(index,id,zhuan) {
				this.$post(this.base+'/prod-api/api/digital-library/library-comment/like',{
					commentId:id,
					like:zhuan
				}).then((res)=>{
				})
				this.commentList[index].myLikeState = !this.commentList[index].myLikeState;
				if (this.commentList[index].myLikeState == true) {
					this.commentList[index].libraryId++;
				} else {
					this.commentList[index].libraryId--;
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.comment {
		display: flex;
		padding: 30rpx;

		.left {
			image {
				width: 64rpx;
				height: 64rpx;
				border-radius: 50%;
				background-color: #f2f2f2;
			}
		}

		.right {
			flex: 1;
			padding-left: 20rpx;
			font-size: 30rpx;

			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10rpx;

				.name {
					color: #5677fc;
				}

				.like {
					display: flex;
					align-items: center;
					color: #9a9a9a;
					font-size: 26rpx;

					.num {
						margin-right: 4rpx;
						color: #9a9a9a;
					}
				}

				.highlight {
					color: #5677fc;

					.num {
						color: #5677fc;
					}
				}
			}

			.content {
				margin-bottom: 10rpx;
			}

			.reply-box {
				background-color: rgb(242, 242, 242);
				border-radius: 12rpx;

				.item {
					padding: 20rpx;
					border-bottom: solid 2rpx $u-border-color;

					.username {
						font-size: 24rpx;
						color: #999999;
					}
				}

				.all-reply {
					padding: 20rpx;
					display: flex;
					color: #5677fc;
					align-items: center;

					.more {
						margin-left: 6rpx;
					}
				}
			}

			.bottom {
				margin-top: 20rpx;
				display: flex;
				font-size: 24rpx;
				color: #9a9a9a;

				.reply {
					color: #5677fc;
					margin-left: 10rpx;
				}
			}
		}
	}
</style>
